<?php


namespace app\api\service;


class Swoole
{
    protected $server;
    public static $user_id;
    public function __construct()
    {
        $this->server= new Swoole\WebSocket\Server("0.0.0.0",6060);
        $this->server->set(array(
            'worker_num'=>12,
        ));
        $this->OpenSocket();
        $this->MessageSocket();
        $this->CloseSocket();
    }

    protected function OpenSocket()
    {
        $this->server->on('open',function (Swoole\WebSocket\Server $server, $request){

        });
    }

    protected function MessageSocket()
    {

        $this->server->on('message', function (Swoole\WebSocket\Server $server, $frame){

        });
    }

    protected function CloseSocket()
    {
        $this->server->on('close', function ($ser, $fd) {
            //用户退出后删除该通道的redis信息
            echo "client {$fd} closed\n";
        });

    }
    public function start()
    {
        $this->server->start();
    }
}